package models

import (
	"time"

	"github.com/astaxie/beego/validation"
)

type FriendLink struct {
	Id        int       `gorm:"primaryKey" json:"id" form:"id"`
	Name      string    `valid:"Required;" json:"name" form:"name"` // 不能为空
	Url       string    `json:"url" form:"url"`
	Sort      int       `json:"sort" form:"sort"`
	Email     string    `json:"email" form:"email"`
	ClientIp  string    `json:"clientIp" form:"clientIp"`
	Status    int       `json:"status" form:"status"`
	CreatedAt time.Time `json:"createdAt" form:"createdAt"`
	UpdatedAt time.Time `json:"updatedAt" form:"updatedAt"`
	DeletedAt time.Time `json:"deletedAt"`
}

func (m *FriendLink) TableName() string {
	return TableName("friend_links")
}

// 自定义验证规则
func (m *FriendLink) SelfValid() (msg interface{}) {
	valid := validation.Validation{}
	if b, _ := valid.Valid(m); !b {
		for _, err := range valid.Errors {
			return err.Message
		}
	}
	return nil
}
